package main

import (
	"fmt"
	"github.com/astaxie/beego/logs"
	"log"
	"golang/oldboy/day11/logagent/tailf"
	"golang/oldboy/day11/logagent/kafka"
)

func main() {
	filename := "/home/simon/golang/src/golang/oldboy/day11/logagent/logagent.conf"
	err := loadConf("ini", filename)
	if err != nil {
		fmt.Printf("load conf failed:,err:%v\n", err)
		panic("load conf failed")
		return
	}

	err = initLogger()
	if err != nil {
		fmt.Printf("load logger failed:,err:%v\n", err)
		panic("load logger failed")
		return
	}

	logs.Debug("load conf succ,config:%v", appConfig)

	err = tailf.InitTail(appConfig.collectConf, appConfig.chanSize)
	if err != nil {
		log.Fatalf("init tail failed,err:%v", err)
		return
	}

	logs.Debug("initialize tailf succ")

	err = kafka.InitKafka(appConfig.kafkaAddr)
	if err != nil {
		log.Fatalf("init kafka failed,err:%v", err)
		return
	}

	logs.Debug("initialize all succ")

	err = serverRun()
	if err != nil {
		logs.Error("serverRun failed,err:%v", err)
		return
	}

	logs.Info("program exited")
}
